﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.FileManipulation
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class FilePathMappingOutput:ResultBase 
    {
        private int _FilePathMapped;
        /// <summary></summary>
        public int FilePathMapped
        {
            get
            {
                return this._FilePathMapped;
            }
            set
            {
                this._FilePathMapped = value;
            }
        }

        public FilePathMappingOutput():base(Guid.Empty,Guid.Empty)
        {
            this._FilePathMapped = 0;
        }

        public FilePathMappingOutput(Guid componentID, Guid jobTicketID,int fileMapped) : base(componentID, jobTicketID)
        {
            this._FilePathMapped = fileMapped;
        }

        #region Overrides of ResultBase

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FilePathMapped", this.FilePathMapped.ToString());

            return xNode;
        }

        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                FilePathMappingOutput output = new FilePathMappingOutput();
                output.OwnerWorkerInstanceID = new Guid(xNode.Attributes.GetNamedItem("WorkerID").Value);
                output.FinishTime = DateTime.Parse(xNode.Attributes.GetNamedItem("FinishTime").Value);

                output.FilePathMapped = int.Parse(xNode.Attributes.GetNamedItem("FilePathMapped").Value);

                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }

        #endregion
    }
}
